/*
 * Created on May 13, 2004
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
package org.pyant.tasks;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;

import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.LogOutputStream;
import org.apache.tools.ant.taskdefs.PumpStreamHandler;

/**
 * @author Ron Smith
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
public class TaskExecuteStreamHandler extends PumpStreamHandler
{
	protected OutputStream os = null;
	protected String script = null;
	
//	protected Thread inputThread = null;
	
	public TaskExecuteStreamHandler(Task task, int outlevel, int errlevel, String script)
	{
		super(new LogOutputStream(task, outlevel),
			  new LogOutputStream(task, errlevel));
		this.script = script;
	}

	public void setProcessInputStream(OutputStream os)
	{
		this.os = os;
	}

	public void start()
	{
		PrintWriter pw = new PrintWriter(this.os);
		pw.println(script);
		pw.close();
		try
		{
			this.os.close();
		}
		catch(IOException ie)
		{
			ie.printStackTrace();
		}
		super.start();
	}



}
